package net.sxnic.ugr.utils;

import net.sxnic.ugr.dept.DeptManager;
import net.sxnic.ugr.security.AuthorizationManager;
import net.sxnic.ugr.user.UserManager;

import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 * User Group Role Manager工具类
 * 
 * @author 孙宇飞
 * 
 */
public class UgrManagerUtils {

	private static UserManager userManager;

	private static DeptManager deptManager;

	private static AuthorizationManager authorizationManager;

	/**
	 * 直接获取UserManager
	 * 
	 * @return
	 */
	public static UserManager getUserManager() {
		if (userManager == null) {
			userManager = (UserManager) WebApplicationContextUtils
					.getRequiredWebApplicationContext(
							ContextLoader.getCurrentWebApplicationContext()
									.getServletContext())
					.getBean("userManager");
		}
		return userManager;
	}

	/**
	 * 直接获取DeptManager
	 * 
	 * @return
	 */
	public static DeptManager getDeptManager() {
		if (deptManager == null) {
			deptManager = (DeptManager) WebApplicationContextUtils
					.getRequiredWebApplicationContext(
							ContextLoader.getCurrentWebApplicationContext()
									.getServletContext())
					.getBean("deptManager");
		}
		return deptManager;
	}

	/**
	 * 直接获取AuthorizationManager
	 * 
	 * @return
	 */
	public static AuthorizationManager getAuthorizationManager() {
		if (authorizationManager == null) {
			authorizationManager = (AuthorizationManager) WebApplicationContextUtils
					.getRequiredWebApplicationContext(
							ContextLoader.getCurrentWebApplicationContext()
									.getServletContext()).getBean(
							"authorizationManager");
		}
		return authorizationManager;

	}

}
